# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=hidapi
pkgver=0.14.0
pkgrel=0
pkgdesc="Simple library for communicating with USB and Bluetooth HID devices"
url="https://github.com/libusb/hidapi"
arch="all"
license="GPL-3.0-only OR BSD-3-Clause"
makedepends="
	cmake
	eudev-dev
	libusb-dev
	linux-headers
	samurai
	"
subpackages="$pkgname-dev"
source="https://github.com/libusb/hidapi/archive/hidapi-$pkgver/hidapi-$pkgver.tar.gz"
options="!check"  # No tests
builddir="$srcdir/hidapi-hidapi-$pkgver"

build() {
	_build build/static -DBUILD_SHARED_LIBS=OFF
	_build build/shared -DBUILD_SHARED_LIBS=ON
}

_build() {
	local outdir=$1; shift

	cmake -B "$outdir" -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		"$@"
	cmake --build "$outdir"
}

package() {
	DESTDIR="$pkgdir" cmake --install build/shared

	DESTDIR=".tmp" cmake --install build/static
	mv .tmp/usr/lib/*.a "$pkgdir"/usr/lib/
}

sha512sums="
66a045144f90b41438898b82f0398e80223323ebfe6e4f197d2713696bb3ae60f36aea5a37a9999b34b12294783fd7e4c28c6e785462559cbe21276009da1eac  hidapi-0.14.0.tar.gz
"
